public class GlovesSelection {
    public int leastGloves(int n, int[] left, int[] right) {
        int total = 0;
        int leftSum = 0;
        int rightSum = 0;
        int leftMin = Integer.MAX_VALUE;
        int rightMin = Integer.MAX_VALUE;

        for (int i = 0; i < n; i++) {
            leftSum += left[i];
            rightSum += right[i];

            if (left[i] != 0 && left[i] < leftMin) {
                leftMin = left[i];
            }

            if (right[i] != 0 && right[i] < rightMin) {
                rightMin = right[i];
            }
        }

        total = Math.min(leftSum, rightSum) + Math.min(leftMin, rightMin) + 1;

        return total;
    }
}